Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 1x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { NextResponse } from "next/server";
import { cookies } from "next/headers";
import { getStrapiURL } from "@/lib/utils";
const config = {
maxAge: 60 * 60 * 24 * 7, // 1 week
path: "/",
domain: process.env.HOST ?? "localhost",
httpOnly: true,
secure: process.env.NODE_ENV === "production",
};
export async function GET(
request: Request,
{ params }: { params: Promise<{ [key: string]: string }> }
) {
const resolvedParams = await params;
console.log("*****************", resolvedParams, "*****************");
const { searchParams } = new URL(request.url);
const token = searchParams.get("access_token");
if (!token) return NextResponse.redirect(new URL("/", request.url));
const provider = resolvedParams.provider;
const backendUrl = getStrapiURL();
const path = `/api/auth/${provider}/callback`;
const url = new URL(backendUrl + path);
url.searchParams.append("access_token", token);
const res = await fetch(url.href);
const data = await res.json();
const cookieStore = await cookies();
cookieStore.set("jwt", data.jwt, config);
return NextResponse.redirect(new URL("/dashboard", request.url));
}
|